import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";

var _dec, _class;

import React, { Component } from 'react';
import { Route, Switch, Redirect } from 'dva/router';
import { connect } from 'dva';
import { getRoutes } from 'utils/utils';
var RouteIndex = (_dec = connect(function (_ref) {
  var global = _ref.global;
  return {
    routerData: global.routerData
  };
}), _dec(_class = /*#__PURE__*/function (_Component) {
  _inherits(RouteIndex, _Component);

  var _super = _createSuper(RouteIndex);

  function RouteIndex() {
    _classCallCheck(this, RouteIndex);

    return _super.apply(this, arguments);
  }

  _createClass(RouteIndex, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          match = _this$props.match,
          routerData = _this$props.routerData;
      var routes = getRoutes(match.path, routerData);
      return /*#__PURE__*/React.createElement(Switch, null, routes.map(function (item) {
        return /*#__PURE__*/React.createElement(Route, {
          key: item.key,
          path: item.path,
          component: item.component,
          exact: item.exact
        });
      }), routes.length > 0 ? /*#__PURE__*/React.createElement(Redirect, {
        key: match.path,
        exact: true,
        from: match.path,
        to: routes[0].path
      }) : null);
    }
  }]);

  return RouteIndex;
}(Component)) || _class);
export { RouteIndex as default };